<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="k" uri="/WEB-INF/k.tld"%>
<%
	
	String path = request.getContextPath();
	
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  
%>
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>怀才进销存管理软件 - 销售前台</title>
		<jsp:include page="../inc.jsp"></jsp:include>
		<script type="text/javascript" src="../My97DatePicker/WdatePicker.js"></script>
		<SCRIPT language="JavaScript" type="text/javascript" src="../web/js/hdm.js"></SCRIPT>
		<script type="text/javascript" src="../jslib/date.js"></script>
		<script type="text/javascript" src="../jslib/jquery.util.js"></script>
		<script type="text/javascript" src="jquery.table.js"></script>
		<link href="../web/css/style.css" rel="stylesheet" type="text/css" />
		<style type="text/css">
			.tabRefresh a{
				display: inline-block;
				font-size: 1px;
				height: 12px;
				opacity: 0.6;
				width: 12px;
			}
			.tabRefresh a:hover{
				background-color:#8DB2E3;
				cursor: pointer;
				opacity: 1;
			}
			
		</style>
		<style media="print" type="text/css">      
              .noprint{     display:none     }      
        </style>
        <OBJECT ID="DLPrinter" CLASSID="CLSID:5C230622-45E5-4e3c-893C-3BFDDC4DB5E4"  codebase="<%=basePath %>sale/DLPrinter.CAB" height="0" width="0" ></OBJECT>
        <!-- 
        	<OBJECT ID="DLPrinter" CLASSID="CLSID:5C230622-45E5-4e3c-893C-3BFDDC4DB5E4"  codebase="http://localhost:8080/jxc/sale/DLPrinter.CAB" height="0" width="0" ></OBJECT>
         -->		
		<script>
		   //打印控件的属性
           DLPrinter.MarginLeft=4;  //左边距
           DLPrinter.MarginRight=4;  //右边距
           DLPrinter.MarginTop=1;  //上边距
           DLPrinter.MarginBottom=1; //下边距
           DLPrinter.CopyCount=1;  //打印份数
           DLPrinter.PageHeader="";  //打印页眉
           DLPrinter.PageFooter="";  //打印页脚
           //DLPrinter.IsLandScape=1;  //1横向打印，0纵向打印         
        </script>
        
		<SCRIPT type="text/javascript" charset="utf-8">
		
		var calendar;
		var dis;
		var discountnum;
		var moneyPointProp = 1;
		var pointMoneyProp = 1;
		var pointDeductionBase = 3000;
		//为了支持java script1.8.1以前版本不支持trim()方法而新增的函数
		String.prototype.trim = function () {
              return this .replace(/^\s\s*/, '' ).replace(/\s\s*$/, '' );
        }

		 function load(){

			 
<%--				$("#box").scroll(function(){--%>
<%----%>
<%--					var title=$("#table_title");--%>
<%--					title.css("top",0);--%>
<%----%>
<%--					//固定表头--%>
<%--					--%>
<%--					--%>
<%--				});--%>
			
				

		}
		$(function(){
			load();
		    /* 获取当前积分策略 */
		    $.post("${pageContext.request.contextPath}/xsgl/pointTacticsAction!noAuthDatagridPointTactics.html", function(data) {
			  var jd = JSON.parse(data)[0];
			  if(jd.moneyPointProp!=null&&Number(jd.moneyPointProp)>0){
			  	moneyPointProp = jd.moneyPointProp;
			  }
			  if(jd.pointMoneyProp!=null&&Number(jd.pointMoneyProp)>0){
			  	pointMoneyProp = jd.pointMoneyProp;
			  }
			  if(jd.pointDeductionBase!=null&&Number(jd.pointDeductionBase)>0){
			  	pointDeductionBase = jd.pointDeductionBase;
			  }
			});
			
            /* 款号自动完成 start $("#searchType").val() */
			$("#searchType").autocomplete("${pageContext.request.contextPath}/spgl/goodsAction!noAuth_noPageAutocomplete.html", { 
					width:240,  
					max:20, 
					minChars:3,
					matchSubset:false,
					dataType: 'json',
					 extraParams: { rid: function() { return $("#rid").val(); }, searchType: function() { return $("#searchType").val(); } },
				    parse: function(data) {
				       var rows = [];
				    	for(var i=0; i<data.length; i++){
				        	rows[rows.length] = {
				                data: data[i],
				                value: data[i].type,
				                result: data[i].type
				            };
				        }
				     return rows;
				     },
				      formatItem: function(item) {
        			return item.type+" 尺码："+item.size+" 颜色："+item.color+" 售价："+item.salePrice;
   					 }
				  }).result( function (event, item, formatted) {
				  	/* 自动填充到barcode */
                      $("#searchBarcode").val(item.barcode);
                 });
                 /* 款号自动完成 end */
                 
			
			$('#uid').val('${sessionInfo.userId}');
			var repertory = '${sessionInfo.repertoryIds}';
			if(repertory&&$('#rid').find('option').length>2){
				$('#rid').find('option').eq(1).attr('selected','selected');
			} 
			$('#date').val((new Date()).pattern("yyyy-MM-dd"));
			if($('#rid').val()!=null&&$('#rid').val()!='undefinded'&&$('#rid').val()!='null'){
				$.ajax({
					url : '${pageContext.request.contextPath}/serial!noAuth_serial.html',
					data : {type : 'XS',rid : $('#rid').val()},
					type : "POST",
					success : function(d){
						$('#serial').val(d);
					}
				});
			}
			calendar = $('#calendar').calendar({
				fit : true,
				current : new Date(),
				border : false,
				onSelect : function(date) {
					$(this).calendar('moveTo', new Date());
				}
			});
			
			/* 修改会员事件 */
			$('#mMobile').keydown(function(e){
				var key = (e.keyCode) || (e.which) || (e.charCode);
				if(key == '13'&&$('#mMobile').val().trim().length>0){
					$.ajax({
						url : '${pageContext.request.contextPath}/hygl/memberAction!noAuth_combobox.html',
						data : {mobile : $('#mMobile').val(),uid :'${sessionInfo.userId}' },
						dataType : 'JSON',
						type : 'POST',
						success : function(d){
							if(d.length>0){
								$('#tishi').html("<span><img src='../web/imgs/hysuccess.gif'  width='15' height='15' /></span>");
								$('#mid').val(d[0].id);
								dis = d[0].discountNum;
								if(d[0].upusertype=='1'){
						 	 		$("#saleGoods tr:gt(0)  td:nth-child(9)").text(dis);
						 	 		discountnum=dis;
						 	 		myUpdateTable();
						 	 	}else{
						 	    	discountnum=10;
						 	 	}
								$('#mtname').val(d[0].tname);
								$('#point').val(d[0].point);
								
								$('#consumePoint').html('');
								for(var i = 0;i*pointDeductionBase<=Number(d[0].point);i++){
									$('#consumePoint').append('<option value="'+i*pointDeductionBase+'">'+i*pointDeductionBase+'</option>');
								}
							}else{
								$('#mMobile').val('');
								sy.messagerAlert('提示', '未找到该会员，建议您新增会员！', 'error');								
							}
						}
					});
				}
				/* 更新账单汇总数据 */
				myUpdateTable();
			});
			
			$('#searchBarcode').keydown(function(e){
				var key = (e.keyCode) || (e.which) || (e.charCode);
				if(key == '13'&&$('#searchBarcode').val().trim().length>0){
					_search();
				}
			});
			
			$('#searchType').keydown(function(e){
				var key = (e.keyCode) || (e.which) || (e.charCode);
				if(key == '13'&&$('#searchType').val().trim().length>0){
					_search();
				}
			});
			
			$('#consumePoint').change(function(){
				//$('#consumePoint').charge();
				charge();
			});
			
			$('#realPay').keydown(function(e){
				var key = (e.keyCode) || (e.which) || (e.charCode);
				if(key == '13'&&$('#realPay').val().trim().length>0){
					//$('#realPay').charge();
					charge();
				}
			});
			$('#wipeZero').keydown(function(e){
				var key = (e.keyCode) || (e.which) || (e.charCode);
				if(key == '13'&&$('#wipeZero').val().trim().length>0){
					//$('#wipeZero').charge();
					charge();
				}
			});
			
		});
		
		function logout(){
			sy.messagerConfirm('请确认', '您确定要退出前台销售？', function(r) {
				if(r){
					$.ajax({
						url : '${pageContext.request.contextPath}/loginAction!logout.html',
						type : 'get',
						success:function(){
							self.location.reload();
							if(window.opener){
								opener.location = opener.location;
							}
							window.close();
						}
					});
				}
			});
		}
		
		var trid = 0;	
		function _search() {
		    var a = 1;
			if($('#rid').val().length<1){
				//$('#rid')[0].focus();
				sy.messagerAlert('提示', '请选择出货仓库！', 'error');
				return;
			}else{
				$('#searchRid').val($('#rid').val());
			}
			
			if($('#searchBarcode').val().trim().length<1&&$('#searchType').val().trim().length<1)
			     return;
			$('#searchForm').form('submit', {
				url : '${pageContext.request.contextPath}/spgl/goodsAction!noAuth_noPageDatagrid.html',
				success : function(d) {			
					var json = $.parseJSON(d);
					var jsonid=0;
					if(json.length>1){						
						$('#mydialog').show(); 
						$('#mydialog').dialog({ 
						collapsible: true, 
						minimizable: false, 
						maximizable: false,
						closable:true,
						closed:false, 
						}); 
						for(var i=0;i<json.length;i++){
							 $('#mytable').datagrid('appendRow',{
							 
					            barcode:json[i].barcode,
					            type:json[i].type,
					            color:json[i].color,
					            size:json[i].size,
							    /*type:json.type,
							    gtname:json.gtname,
							    bname:json.bname,
							    name:json.name,
							    unit:json.unit,
							    color:json.color,
							    size:json.size,
							    //num:'1'
							    num:tempnum*/
						     });
						}						
						$("#mytable").datagrid({
							onDblClickRow:function(rowIndex, rowData){
								searchAdd(json,rowIndex);
								top.closeMytableDialog();
							}
						});	
							 
					}else{
						searchAdd(json,jsonid);	
					}
									
					function searchAdd(json,jsonid){ 
						var gid = [];	
					    var flag = 0;	
					    if(json[jsonid].discountNum!=null&&json[jsonid].discountNum!='undefinded'){
				 	 	    if(json[jsonid].upusertype==5){
				 	 		    discountnum=json[jsonid].discountNum;
				 	 	    }	
				 	    }else{
				 	        if(json[jsonid].upusertype==1){
					 	   	    if(discountnum!=null&&discountnum!='undefinded'){
						 	   	    if(dis!=null&&dis!='undefinded'){
						 	 		    discountnum=dis;
						 	 	    }
					 	 	    }else{
					 	 		    discountnum=10;
					 	 	    }
				 	 	    }else{
				 	 		    discountnum=10;
				 	 	    }
				 	    }
					    if(json[jsonid].id!=null){
					        var flagTmep = 0;
					        var table = document.getElementById("saleGoods").rows.length-1;
				            for(var i=0;i<table;i++){
				              gid.push($("#saleGoods tr:eq("+ (i+1) +") td:nth-child(1)").text());
				            }
					        for(var i = 0;i < gid.length; i ++){
					            if(json[jsonid].id == gid[i]){
					               flagTmep = 1;	
					               flag = 1;				         
					            }
					        }	 			   			   
					    }
                        if(flag == 1){
					        for(var i=0;i<gid.length;i++){
						       if(json[jsonid].id==gid[i]){						      
						           var tempa = $("#saleGoods tr:eq("+ (i+1) +") td:nth-child(11)").text();//数量
							       a = parseInt(tempa) + 1;
							       $("#saleGoods tr:eq("+ (i+1) +") td:nth-child(11)").text(a);
 							       //$("#saleGoods tr:eq("+ (i+1) +") td:nth-child(9)").text('￥'+$.multiply(json[jsonid].showPrice,discountnum*0.1*a));
 							       $('#searchBarcode').val('');
					               $('#searchType').val('');
 							       $("#searchBarcode").focus();
 							       myUpdateTable(); 
						       }
					        }	   	
					    }else{
					        /*$('#saleGoods').addRow({
							     td:[
								{text:json[jsonid].id,hidden:true},//
								{text:json[jsonid].barcode},//条码
								{text:json[jsonid].type},//款号
								{text:json[jsonid].name},//名称
								{text:json[jsonid].bname},//品牌
								{text:json[jsonid].color},//颜色
								{text:json[jsonid].size},//尺码
								{text:'￥'+json[jsonid].showPrice},//吊牌价
								{text:$.multiply(discountnum,1)},//折扣
								{text:parseFloat(json[jsonid].showPrice*discountnum*0.1).toFixed(1),editable:true},//单价
								{text:a,editable:true},//数量
								{text:'￥'+parseFloat(json[jsonid].showPrice*discountnum*0.1).toFixed(1)}//金额
								]
						    });*/
						    trid++; 
						    $("#saleGoods").append("<tbody id='tbody"+trid+"'><tr id='tr"+trid+"'><td style=\"display:none;\">"+json[jsonid].id+"</td><td>"+json[jsonid].barcode+
						     "</td><td align='center'>"+json[jsonid].type+"</td><td align='center'>"+json[jsonid].name+"</td><td align='center'>"+json[jsonid].bname+
						     "</td><td align='center'>"+json[jsonid].color+"</td><td align='center'>"+json[jsonid].size+"</td><td align='center'>￥"+json[jsonid].showPrice+
						     "</td><td align='center'>"+$.multiply(discountnum,1)+
						     "</td><td align='center'>"+parseFloat(json[jsonid].showPrice*discountnum*0.1).toFixed(1)+
						     "</td><td align='center'>"+a+"</td><td align='center'>￥"+parseFloat(json[jsonid].showPrice*discountnum*0.1).toFixed(1)+
						     "</td><td align='center'><a href='javascript:void(0)' onclick='removeRow("+trid+")'>移除</a></td></tr></tbody>"); 
						
					    }					    
					    myUpdateTable();					    
					        
					    //saleGoods td 的区域点击可以编辑功能 start
					    var content;                        
                        $("#saleGoods tr:gt(0)  td:nth-child(11)").click(function(){ 
                            var temp = $(this).text();
                            var clickObj = $(this);                          
                            content = clickObj.html();                            
                            changeToEdit(clickObj,temp);  
                            //myUpdateTable();                                                
                        });			      
                         $("#saleGoods tr:gt(0)  td:nth-child(10)").click(function(){ 
                         var temp = $(this).text();
                         var clickObj = $(this);                          
                         content = clickObj.html();
                          /* for(var i=0;i<gid.length;i++){
							  $("#saleGoods tr:eq("+ (i+1) +") td:nth-child(9)").text('￥'+$.multiply(json[jsonid].showPrice,discountnum*0.1*content));
						  } */
						  myUpdateTable();
                         changeToEdit(clickObj,temp);   
                                               
                    });      
                        function changeToEdit(node,temp){ 
                            node.html(""); 
                            var inputObj = $("<input type='text'/>"); 
                            inputObj.css("background-color",node.css("red")).css("font-size",node.css("font-size"))
                                    .css("width",node.css("width")).val(content).appendTo(node).get(0).select(); 
                            inputObj.val(temp);
                            /*  for(var i=0;i<gid.length;i++){
							     $("#saleGoods tr:eq("+ (i+1) +") td:nth-child(9)").text('￥'+$.multiply(json[jsonid].showPrice,discountnum*0.1*content));
						    } */
						    //myUpdateTable();
                            inputObj.click(function(){
                                return false; 
                            }).keyup(function(event){ 
                                var keyvalue = event.which; 
                                if(keyvalue==13){ //按了ENTER键
                            		 var aa = node.children("input").val().replace(/[^0-9]+/g,"");
                                     node.html(aa); 
                                     myUpdateTable();
                                     /* for(var i=0;i<gid.length;i++){
									 	 $("#saleGoods tr:eq("+ (i+1) +") td:nth-child(9)").text('￥'+$.multiply(json[jsonid].showPrice,discountnum*0.1*aa));
								 	 } */
                                } 
                                if(keyvalue==27){ //按了ESC键
                                     node.html(content); 
                                } 
                                
                            }).blur(function(){ 
                                if(node.children("input").val()!=content){
                                     var aa = node.children("input").val().replace(/[^0-9]+/g,"");
                                     //if(confirm("是否保存修改的内容？","Yes","No")){ 
                                     node.html(aa);
                                     /*  for(var i=0;i<gid.length;i++){
									    $("#saleGoods tr:eq("+ (i+1) +") td:nth-child(9)").text('￥'+$.multiply(json[jsonid].showPrice,discountnum*0.1*aa));	
 								     } */
 								 	 myUpdateTable();
                                }else{ 
                                     node.html(content); 
                                } 
                            }); 
                        } 
                        //saleGoods td 的区域点击可以编辑功能   end

                    	//对总金额再次计算
						charge();
                        
				    }
		        }	
			});
			$("#searchBarcode").focus();
		}
		/*移除一行*/
		function removeRow(th){
			document.getElementById("tbody"+th).removeChild(document.getElementById("tr"+th)); 
			myUpdateTable();
			$('#charge').val(0);
		}
		
		/* 更新表格数据和汇总 */
		function myUpdateTable(){
		    $('#searchBarcode').val('');
		    $('#searchType').val('');
			var sgl1 = $("#saleGoods tr").length;
			for(var i=1;i<sgl1;i++){
				$("#saleGoods tr:eq("+i+") td:eq(11)").text("￥"+parseFloat(($("#saleGoods tr:eq("+i+") td:eq(10)").text())*($("#saleGoods tr:eq("+i+") td:eq(9)").text())).toFixed(1));
		    }
		    charge();
			updateTableData();
		}
		/* 销售列表更新收款区域数据 */
		function updateTableData(){
			var rows = $("#saleGoods tr").length; 
			var totalMoney = '0.00',totalGoods = '0',totalPay = '0.00',totalDiscount = '0.00',Point = '0',beforeTotalPoint = $('#point').val();
			
			for(var i = 1;i<rows;i++){
			    var count   = $("#saleGoods tr:eq("+ i +") td:nth-child(11)").text(); //商品数量
			    totalGoods = parseInt(totalGoods)+parseInt(count);
			    
			    var totalPayText = $("#saleGoods tr:eq("+ i +") td:nth-child(12)").text();//总计
			    totalPay = parseFloat(parseFloat(totalPay)+parseFloat(parseFloat(totalPayText.substring(1,totalPayText.length)).toFixed(1))).toFixed(1); 
			    
			    var totalMoneyText = $("#saleGoods tr:eq("+ i +") td:nth-child(8)").text();//售价：￥
			    var money = parseFloat(parseFloat(totalMoneyText.substring(1,totalMoneyText.length)).toFixed(1))*parseInt(count);
			    totalMoney = parseFloat(parseFloat(totalMoney)+parseFloat(money)).toFixed(1);
			    
			    var index = totalPay.toString().indexOf("."); //本次积分
				if(index!=-1){
					Point = totalPay.toString().substring(0,index);
				}else{
					Point = totalPay.toString();
				}				
				Point = Math.floor(Point/moneyPointProp);		    
			}            
			$('#totalGoodsSpan').html(totalGoods);  //商品数量
			$('#totalPaySpan').html(totalPay);   //总计：￥
			$('#totalMoneySpan').html(totalMoney);  //售价：￥
			$('#totalDiscountSpan').html(parseFloat(totalMoney-totalPay).toFixed(1));  //优惠金额：￥
			$('#PointSpan').html(Point);  //本次积分
			var temptotalPointSpan = parseInt(Point) + parseInt(beforeTotalPoint);
			$('#totalPointSpan').html(temptotalPointSpan);  //累计积分
			$('#shouldPay').val(totalPay);  //应收

			//设置滚动条到最底部
			//alert($("#box").height());
			
			$("#box").scrollTop($("#saleGoods").height());
			
		}
		
		/* 收款、抹零、积分点数事件更新收款区域数据 */
		function charge(){
			
			var charge = Number('0.0');
			var shouldPay = Number($('#shouldPay').val());
			var wipeZero = $('#wipeZero').val().trim().length<1&&((Number($('#wipeZero').val().trim())+"")=="NaN")?Number(0):Number($('#wipeZero').val().trim());
			var realPay = $('#realPay').val().trim().length<1&&((Number($('#realPay').val().trim())+"")=="NaN")?Number(0):Number($('#realPay').val().trim());
			var consumePoint = Number($('#consumePoint').val()); //积分点数
			var pointMoney = consumePoint/pointMoneyProp;
			pointMoney = jQuery.multiply(pointMoney,1);
			shouldPay = jQuery.reduce(shouldPay,pointMoney);
			shouldPay = jQuery.reduce(shouldPay,wipeZero);//此时shouldpay的值表示去掉积分抵现和抹零后客户真正要支付的钱
			if(shouldPay<=realPay){
				if(shouldPay<=0){
					charge = realPay;
				}else{
					charge = jQuery.reduce(realPay,shouldPay);
				}
			}else{
				charge = jQuery.reduce(realPay,shouldPay);
				if(charge>realPay)
				charge = realPay;
			}
			//要先付款才显示找零
			if(realPay!=0){
				$('#charge').val(charge); //找零
			}
			
			$('#PointSpan').html(Math.floor(($('#realPay').val()-$('#charge').val())/moneyPointProp)); //本次积分
		}
		
		function cancelAll(){
			sy.messagerConfirm('请确认', '您确定要取消此次销售，之前输入所有数据将会丢失？', function(r) {
				if(r){
					self.location.reload();
				}
			});
		}
		
		/* 结算 */
		function submitSale(printnum){
			if(!$('#saleForm').form("validate")){
				return;
		}
			
			sy.messagerConfirm('请确认', '您确定要结算？', function(r) {
				if(r){
					grandTable();
					if($('#Charge').val()<0||$('#realPay').val()==null||$('#realPay').val()=='undefined'||$('#realPay').val()==''){
						sy.messagerAlert('提示', '该客户还未付清款项！', 'error');
						return;
					}
					$('#remarkBak').val(encodeURIComponent($('#remark').val()));
					var vip = $('#totalDiscountSpan').html();
					if(!isNaN(vip)&&vip!=null&&vip!='undefinded'&&vip!='null'){
						$('#Viptotal').val(vip);
					}else{
						$('#Viptotal').val(0);
					}
					$('#saleForm').form('submit', {
						url : '${pageContext.request.contextPath}/xsgl/salelistAction!noAuth_add.html',
						success : function(d) {
							var json = $.parseJSON(d);
							if(json.success==true){
								parent.sy.messagerShow({
									title : '提示',
									msg : json.msg
								});
								if(printnum!=0){
									print();
									window.setTimeout('print()',3000);
									window.setTimeout('self.location.reload()',4000);
								}else{
									window.setTimeout('self.location.reload()',1000);
								}
								
							}else{
								parent.sy.messagerShow({
									title : '提示',
									msg : json.msg
								});
							}
						}
					});
					
				}
			});
		}
		
		/* 结算 */
		function grandTable(){
			var items = [];
			var rows = $("#saleGoods tr").length;
			for(var i = 1;i<rows;i++){
			    var goodid   = $("#saleGoods tr:eq("+ i +") td:nth-child(1)").text(); //商品编号
				items.push(goodid);
				
				var goodprice   = $("#saleGoods tr:eq("+ i +") td:nth-child(10)").text(); //商品单价
				items.push(goodprice);
				
				var goodnumber   = $("#saleGoods tr:eq("+ i +") td:nth-child(11)").text(); //数量
				items.push(goodnumber);
				
				var goodmoney   = $("#saleGoods tr:eq("+ i +") td:nth-child(12)").text(); //金额
				items.push(goodmoney.substring(1,goodmoney.length));
			}
				
			$('#Items').val(items.join(','));
			$('#Total').val($('#shouldPay').val());
			$('#RealPay').val($('#realPay').val());
			$('#Charge').val($('#charge').val());
			$('#PointNum').val($('#consumePoint').val());
			$('#WipeZero').val($('#wipeZero').val());
						
		}
		
		/* 结算打印 */
		function print() {
            //var trcount = $("#saleGoods tr").length;                     
            //var goodCount = parseInt(trcount)-1; //购买商品条数           
		    //var url = "http://127.0.0.1:8080/jxc/sale/x.jsp?goodCount="+goodCount+"&id="+slid;
            DLPrinter.ContentURL="<%=basePath %>sale/x.jsp";            
          	DLPrinter.PrintDirect(); //直接打印不出现打印选择对话框
            //DLPrinter.PrintPreview(); //打印预览
        }
        
		/* 新增会员 start */
		function createMember(){

			
			if(!$('#memberForm').form("validate"))
			
				return;


			//判断积分不为负数
			var point=$("#memberForm").find("#point").eq(0);

				var pointNum=parseInt(point.val());

				if(isNaN(pointNum)){
					alert("你输入的积分不合法请重新输入！");
					$(point).focus();
					return;
				}
				
				if(pointNum<0){
					alert("积分不能为负数！");
					$(point).focus();
					return;
				}
				
			sy.messagerConfirm('请确认','您确认要新增该会员?',function(r){
				if(r){
					$('#name').val(encodeURIComponent($('#name').val()));
					$('#mRemark').val(encodeURIComponent($('#mRemark').val()));
					$('#address').val($('#address').val());
					$('#memberForm').form('submit', {
						url : '${pageContext.request.contextPath}/hygl/memberAction!add.html',
						type : "POST",
						success : function(d) {
							closeDiv();
							var json = $.parseJSON(d);
							$('#mMobile').val(json.obj.mobile);
							$('#mid').val(json.obj.id);
							$('#mtid').val(json.obj.tid);
							$('#point').val(json.obj.point);
						
							$('#consumePoint').html('');
							for(var i = 0;i*pointDeductionBase<=Number(json.obj.point);i++){
								$('#consumePoint').append('<option value="'+i*pointDeductionBase+'">'+i*pointDeductionBase+'</option>');
							}
							sy.messagerAlert('新增会员成功', '您新增的会员信息如下：<br/><br/>会员编号：'+json.obj.serial+'<br/>会员姓名：'+json.obj.name+'<br/>会员生日: '+json.obj.birthdayA+'<br/>初始积分：'+(json.obj.point?json.obj.point:'0')+'<br/>会员地址：'+(json.obj.address?json.obj.address:''), 'info');							
						}
					});
				}
			});	
			/* 新增会员 end */
			
		}
		
		
		function closeMytableDialog() { 
			$("#mytable").datagrid('loadData',{total:0,rows:[]});					
			$('#mydialog').dialog({
				closed:true,
			 });
			$("#searchBarcode").focus();
		} 

		</SCRIPT>
	</head>

	<body>
		<div class="top">
			<div class="logo">
				<img src="../web/imgs/htlogo.jpg" width="480" height="47" />
			</div>
			<div class="right">
				欢迎您！${sessionInfo.loginName} [${sessionInfo.roleNames}]
				<a href="javascript:void(0)" onclick="logout()">退出登录</a>
				<!-- 
					<a href="#">修改密码</a>
				 -->
			</div>
		</div>
		<div class="content">
			<div class="right">
				<!--日历标题-->
				<div class="title">
					<img src="../web/imgs/pic1.gif" width="6" height="6" />
					日历
				</div>
				<!--/日历标题-->
				<!--日历-->
				<div style="height:180px;">
					<div id="calendar"></div>
				</div>
				<!--/日历-->
				<!--公告+提醒-->
				<div class="title">
					<ul>
						<li id="cp1" class="cpover" onMouseOver="setTab_('cp',1,5,'cpover')">
							公告<span class="tabRefresh"><a href="javascript:void(0);" onclick="javascript:document.frames('announcementIframe').location.reload()" class="icon-mini-refresh"></a></span>
						</li>
						<li id="cp2" onMouseOver="setTab_('cp',2,5,'cpover')">
							系统提醒<span class="tabRefresh"><a href="javascript:void(0);" onclick="javascript:document.frames('warnIframe').location.reload()" class="icon-mini-refresh"></a></span>
						</li>
					</ul>
				</div>
				<div class="conts">
					<div id="cp_con1">
						<iframe width="100%" height="400px;" scrolling="auto" frameborder="0" onload="javascript:void(0);" name="announcementIframe" id="announcementIframe" src="${pageContext.request.contextPath}/qtmk/announcementAction!noAuth_tabAnnounce.html"></iframe>
					</div>
					<div id="cp_con2" style="display: none;">
						<iframe width="100%" height="400px;" scrolling="no"  frameborder="0" onload="javascript:void(0);" name="warnIframe" id="warnIframe" src="${pageContext.request.contextPath}/qtmk/remindWarnAction!noAuth_tabRemindWarn.html"></iframe>
					</div>
				</div>
				<!--/公告+提醒-->
			</div>
			<div class="left">
				<div class="nav">
					<ul>
						<k:security key="XSGL_QTXS">
						<li>
							<a href="${pageContext.request.contextPath}/xsgl/sale.html">
								<img src="${pageContext.request.contextPath}/web/imgs/navxsgl.jpg" width="104" height="35" /> 
							</a>
						</li>
						</k:security>
						<k:security key="XSGL_XSTH">
						<li>
							<a href="${pageContext.request.contextPath}/xsgl/saleReturn.html">
								<img src="${pageContext.request.contextPath}/web/imgs/nav-xsth.jpg" width="104" height="35" /> 
							</a>
						</li>
						</k:security>
						<k:security key="XSGL_KCCX">
						<li>
							<a href="${pageContext.request.contextPath}/xsgl/amount.html">
								<img src="${pageContext.request.contextPath}/web/imgs/nav-kcgl.jpg" width="104" height="35" /> 
							</a>
						</li>
						</k:security>
						<k:security key="XSGL_HYGL">
						<li>
							<a href="${pageContext.request.contextPath}/xsgl/member.html">
								<img src="${pageContext.request.contextPath}/web/imgs/nav-hygl.jpg" width="104" height="35" /> 
							</a>
						</li>
						</k:security>
						<k:security key="XSGL_RJQS">
						<li>
							<a href="${pageContext.request.contextPath}/xsgl/settlement.html">
								<img src="${pageContext.request.contextPath}/web/imgs/nav-rjqs.jpg" width="104" height="35" /> 
							</a>
						</li>
						</k:security>
						<k:security key="XSGL_XSJLCX">
						<li>
							<a href="${pageContext.request.contextPath}/xsgl/salelist.html">
								<img src="../web/imgs/navxsglcx.jpg" height="35" /> 
							</a>
						</li>
						</k:security>
						<k:security key="XSGL_THJLCX">
						<li>
							<a href="${pageContext.request.contextPath}/xsgl/saleReturnlist.html">
								<img src="../web/imgs/navthglcx.jpg" height="35" /> 
							</a>
						</li>
						</k:security>
					</ul>
				</div>
				<div class="cont"><div style=" overflow: hidden;">
					<!--营业员信息-->
					<form id='saleForm'>
					<input type='hidden' id='Items' name='items' value=''/>
					<input type='hidden' id='Total' name='total' value=''/>
					<input type='hidden' id='RealPay' name='realPay' value=''/>
					<input type='hidden' id='Charge' name='charge' value=''/>
					<input type='hidden' id='Point' name='point' value=''/>
					<input type='hidden' id='PointNum' name='pointNum' value=''/>
					<input type='hidden' id='WipeZero' name='WipeZero' value=''/>
					<input type="hidden" id="Viptotal" name="viptotal">
					<table border="0" cellspacing="4" class="table" >
						<tr>
							<td width="90" align="right" class="lanse">
								营 业 员：
							</td>
							<td >
								<label for="select"></label>
								<select name="uid" class="width1 easyui-validatebox" id="uid" data-options="required:'true',missingMessage:'请选择营业员'">
									<option value="">&nbsp;</option>
								<c:forEach items="${VUsers}" var="VUser">
									<option value="${VUser.id }">${VUser.username }</option>
								</c:forEach>
								</select>
							</td>
							<td width="72" align="right" class="lanse">
								销售日期： 
							</td>
							<td >
								<input id="date" name='date'  onClick="WdatePicker()" class='easyui-validatebox' data-options="required:'true',missingMessage:'请选择销售时间'"/>
							</td>
							<td width="72" align="right" class="lanse">
								销售单号：
							</td>
							<td >
								<input name="serial"  type="text" style="width: 140px" class="input1 easyui-validatebox" readonly="readonly" id="serial"  value="${serial }" data-options="required:'true',missingMessage:'请输入销售单号'"/>
							</td>
							<td rowspan="3" valign="top" class="addvip">
<!-- 								添加会员 -->
								<a href="javascript:showDiv()"><img src="../web/imgs/addvip.jpg" width="104" height="100" /> </a>
							</td>
						</tr>
						<tr>
							<td align="right">
								会&nbsp;&nbsp;&nbsp;&nbsp;员：
							</td>
							<td>
								<label for="textfield"></label>
								<input name="mMobile" type="text" class="input1" id="mMobile" /><input name="mid" type="hidden" id="mid" />
								<span id="tishi"></span>
							</td>
							<td align="right">
								会员积分：
							</td>
							<td>
								<input type="text" class="input1" value='0' id="point" readonly="readonly"/>
							</td>
							<td align="right">
								会员类型：
							</td>
							<td>
								<input type="text" class="input1" value=''style="width: 140px"  id="mtname" readonly="readonly"/>
<%-- 								<select name="mtid" class="width1 easyui-validatebox" id="mtid">
									<option value='mtid'></option>
									<c:forEach items="${VMemberTypes}" var="VMemberType">
										<option value='${VMemberType.id }'>${VMemberType.name }</option>
									</c:forEach>
								</select> --%>
							</td>
						</tr>
							<td align="right" valign="top">
								备&nbsp;&nbsp;&nbsp;&nbsp;注：
							</td>
							<td colspan="3">
								<textarea id="remark" cols="61" rows="1"></textarea>
								<textarea name="remark" id="remarkBak" style="display:none;"></textarea>
							</td>
							<td align="right" valign="top" class="lanse">
								出货仓库：
							</td>
							<td valign="top">
								<select name="rid" style="width: 140px"  class="width1 easyui-validatebox" id="rid" data-options="required:'true',missingMessage:'请选择出货仓库'">
<!--									<option value=''></option>-->
									<c:forEach items="${VRepertories}" var="VRepertory">
										<option value='${VRepertory.id }'>${VRepertory.name }</option>
									</c:forEach>
								</select>
							</td>
						</tr>
					</table>
					</form>
					<!--/营业员信息-->
					<!--销售单信息-->
					<div id="box" style="height:237px; OVERFLOW-Y: auto; OVERFLOW-X:hidden;">
						<table  border="1"  bordercolor="#eee" cellpadding="0" id="saleGoods" cellspacing="0" class="table info" style="border-collapse: collapse" >
							<thead id="table_title">
							<tr class="title" >
									<td style="display:none;" >
									&nbsp;
									</td>
									<td style="border:none;width: 300px" >
										&nbsp;&nbsp;&nbsp;条形码
									</td>
									<td align="center">
										款号
									</td>
									<td align="center">
										商品名称
									</td>
									<td align="center">
										品牌
									</td>
									<td align="center">
										颜色
									</td>
									<td align="center">
										尺码
									</td>
									<td align="center">
										吊牌价
									</td>
									<td align="center">
										折扣
									</td>
									<td align="center">
										  单  价
									</td>
									<td align="center">
										数量
									</td>
									<td align="center">
										总金额
									</td>
									<td align="center">
										移除
									</td>
								</tr>
								</thead>
						</table>
					</div>
					<!--/销售单信息-->
					<!--手动输入货单信息-->
					<form id="searchForm" >
						<input type='hidden' id='searchRid' name='rid'/>
						<table border="0" cellpadding="4" class="table huodanxx">
							<tr>
								<td width="100" align="right">
									条形码：
								</td>
								<td width="240">
									<input name="barcode" type="text" class="input1" id="searchBarcode" />
									<input type='hidden' id='jsonid' name='jsonid' value=''/>
									
								</td>
								<td width="69" align="right">
									款号：
								</td>
								<td width="240">
									<input name="type" type="text" class="input1" id="searchType" />
								</td>
								<td>
									<a href="#">
										<img src="../web/imgs/anniu4.gif" width="20" height="20" onclick="_search()"/> 
									</a>
								</td>
							</tr>
						</table>
					</form>
					<!--/手动输入货单信息-->
					<!--结算-->
					<div class="jiesuan">
						<div class="leftjs">
							<h2>
								总计：￥<span id='totalPaySpan'>0.00</span>
							</h2>
							商品数量：<span id='totalGoodsSpan'>0</span> 售价：￥<span id='totalMoneySpan'>0.00</span> 优惠金额：￥<span id='totalDiscountSpan'>0.00</span>
							<br />
							本次积分：<span id='PointSpan'>0</span> 累计积分：<span id='totalPointSpan'>0</span>
							<a href="#" class="button1 dis_block">会员信息 >></a>
						</div>
						<div class="centjs">
							<table width="100%" border="0" class="jsxx">
								<tr>
									<td>应收：</td>
									<td>
										￥<input name="shouldPay" type="text" class="input1" id="shouldPay" value="0.00" readonly="readonly" />
									</td>
									<td>支付方式：</td>
									
									<td>
										<select name="select5" class="input1" class="width2 " id="select5">
											<option>
												现金
											</option>
										</select>
									</td>
								</tr>
								<tr>
									<td>实收：</td>
									<td>
										￥<input name="realPay" type="text" class="input1" id="realPay" value="" />
									</td>
									<td>积分点数：</td>
									<td>
										<select name="consumePoint" class="input1" id="consumePoint">
											<option value='0'>0</option>
										</select>
									</td>
									<td>&nbsp;</td>
								</tr>
								<tr>
									<td>找零：</td>
									<td>
										￥<input name="charge" type="text" class="input1" id="charge" value="0.00" readonly="readonly" />
									</td>
									<td>抹零金额：</td>
									<td>
										<input name="wipeZero" type="text" class="input1" id="wipeZero" value="" />
									</td>
									
									<td>&nbsp;</td>
								</tr>
							</table>
						</div>
						<div class="rightjs">
							<ul>
								<li>
									<a href="javascript:void(0);" onclick="submitSale(0)" class="button2 dis_block">结算</a>
								</li>
								<li>
									<a href="javascript:void(0);" onclick="submitSale(2)" class="button2 dis_block">结算打印</a>
								</li>
								<li>
									<a href="javascript:void(0);" onclick="cancelAll()" class="button3 dis_block">取 消</a>
								</li>
							</ul>
						</div>
					</div>
					<!--/结算--></div>
				</div>
			</div>
		</div>
		<br/><br/><br/>
		<div class="foot" >
			Copyright @ 2013
			<a style="color:#FFFFFF; text-decoration:none;" target="_blank" href="http://www.miitbeian.gov.cn">浙ICP备13002014号-1</a>
			<br>
			杭州怀才商贸有限公司 服务电话：0571-28030726
		</div>
		
		<script language="javascript" type="text/javascript">		
		function showDiv(){
			$('#storename').val($('#rid :selected').text());
			//alert($('#rid :selected').text()+" - "+$('#rid :selected').val());
			$('#rid2').val($('#rid :selected').val());
			$.ajax({
				url : '${pageContext.request.contextPath}/serial!noAuth_serial.html',
				data : {type : 'HY',rid :$('#rid').val()},
				type : "POST",
				success : function(d){
					$('#memSerial').val(d);
				}
			});
							
			document.getElementById('popDiv').style.display='block';
			document.getElementById('popIframe').style.display='block';
			document.getElementById('bg').style.display='block';
		}
		function closeDiv(){
			document.getElementById('popDiv').style.display='none';
			document.getElementById('bg').style.display='none';
			document.getElementById('popIframe').style.display='none';
			document.getElementById('memberForm').reset();
		}
		</script>
		<!--弹出框信息-->
		<div id="popDiv" class="mydiv" style="display: none;">
			<div class="title">
				<a href="javascript:closeDiv()">关闭窗口</a>新增会员
			</div>
			<div class="cont">
				<form id="memberForm" method="post">
				<table width="100%" border="0">
					<tr>
<!-- 					    <td align="right">办卡日期：<br></td> -->
<!-- 					    <td><input type="text" id="openDate" class="input1 easyui-validatebox" onClick="WdatePicker()" name="openDate" data-options="required:'true',missingMessage:'请选择办卡日期'"/><br></td> -->
					    <td align="right">会员编号：<br></td>
					    <td><input type="text" id="memSerial" style="width: 140px"  readonly="readonly" class="input1 easyui-validatebox" name="serial"><br></td>
					    <td align="right">客户姓名：<br></td>
					     <td><input id="name" class="input1 easyui-validatebox" name="name" data-options="required:'true',missingMessage:'请输入客户姓名'"><br></td>
					  </tr>
					  <tr>
					    <td align="right">会员类别：<br></td>
					    <td>
					    
					    	<select style="width: 140px"  name="tid" class="input1 easyui-validatebox" style="width: 130px" id="tid" data-options="required:'true',missingMessage:'请选择会员类型'">
									<c:forEach items="${VMemberTypes}" var="VMemberType">
										<option value='${VMemberType.id }'>${VMemberType.name }</option>
									</c:forEach>
								</select>
						<br></td>
					    <td align="right">手&nbsp;&nbsp;&nbsp;&nbsp;机：<br></td>
					    <td><input type="text" id="mobile" class="input1" name="mobile"><br></td>				    
					  </tr>
					  <tr>
    					<td align="right">生&nbsp;&nbsp;&nbsp;&nbsp;日：<br></td>
					    <td><input type="text" id="birthdayA" style="width: 140px"  class="input1" onclick="WdatePicker({dateFmt:'MM-dd'})" name="birthdayA"><br></td>
					    <td align="right">商店名称：<br></td>
					    <td ><input name="storename" readonly="readonly" id="storename" class="input1"><br>
					    	<input name="rid" type="hidden" id="rid2"/>
					    </td>
					  </tr>
					   <tr>
					    <td align="right">积&nbsp;&nbsp;&nbsp;&nbsp;分：<br></td>
					    <td colspan="3"><input style="width: 140px"  name="point" id="point" class="input1"/><br></td>		  	
					  </tr>
					  <tr>
					    <td align="right">地&nbsp;&nbsp;&nbsp;&nbsp;址：<br></td>
					    <td colspan="3"><textarea type="text" id="address" name="address"  rows="1" style="width: 440px"></textarea><br></td>		  	
					  </tr>
					  <tr>
					 	<td align="right">备&nbsp;&nbsp;&nbsp;&nbsp;注：<br></td>
					  	<td colspan="3"><textarea type="text"  name="remark" id="mRemark" rows="1" style="width: 440px"></textarea> <br></td>
					  </tr>
					   <tr>
					    <td  colspan="3">&nbsp;<br><br></td>
					    <td align="right"><a href="javascript:void(0);" onclick="createMember()" class="button2 dis_block">添加</a><br></td>
					  </tr>
				</table>
				</form>
			</div>
		</div>
		<div id="bg" class="bg" style="display: none;"></div>
		<div id="mydialog" style="display:none;padding:5px;width:400px;height:auto;min-height:150px;max-height:200px;overflow-y:scrooll;" title="亲！该条码对应了多件商品，请双击您要销售的商品。">		 		
		<table id="mytable" class="easyui-datagrid" style="height:auto"  data-options="iconCls: 'icon-edit',singleSelect: true"> 
		        <thead>
		            <tr>
		            	<th data-options="field:'barcode',width:100">商品条码</th>  
		            	<th data-options="field:'type',width:100">款号</th>  
	                 	<!-- <th data-options="field:'name',width:100">商品名称</th> 
	                 	<th data-options="field:'bname',width:80">品牌</th> -->
                   		<th data-options="field:'color',width:80,align:'center'">颜色</th>
                   		<th data-options="field:'size',width:80,align:'center'">尺码</th>
		            </tr>
		        </thead>
		    </table>
		</div> 
		<iframe id='popIframe' class='popIframe' frameborder='0'></iframe>
		<!-- datetime: 2013年7月14日 09:37:35  -->
	</body>
</html>
